//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<ImageResource.h>
///	@path	~/src/gui/image/
///	@date	2008/06/25
///	@desc	.

#pragma once

#include "xeres.h"

#include "lib/utilities/string.h"
#include "lib/utilities/dict.h"
#include "lib/utilities/time.h"
#include "lib/system/lock.h"

#include "database/DataManager.h"

#include "gui/image/IBitmap.h"

namespace xeres {

	/*! 
		\class	ImageResource
		\brief	Manages & caches image resource.
	*/
	class ImageResource
	{
	public:

		/// \ctor
		ImageResource( void );

		/// \dtor
		~ImageResource( void );

	public:

		/*! 
			\brief	Loads an image by providing path.
		*/
		RefWeak<IBitmap> LoadImage( const WString& path , int frames = 0 , int starts = 0 );

		typedef function< RefPass<IBitmap>(const WString&,int,int) > Loader;

		/*! 
			\brief	Register loader.
		*/
		bool RegisterLoader( const WString& ext , Loader loader );

	private:

		//@ data

		/// \brief	Image booking structure.
		struct Image
		{
			Ref<IBitmap>			m_bitmap;
			size_t					m_imageSize;
			Time					m_lastLoad;
			Time					m_lastAccess;
		};
		
		ThreadLock					m_lock;
		dict< WString , Image * >	m_images;
		dict< WString , Loader >	m_loaders;
		
	};

} // namespace xeres
